﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace PhotoGallery.Core.Business
{
    public class RoleIndexModel
    {
        /// <summary>
        /// 角色列表
        /// </summary>
        public IList<Role> Roles { get; set; }

        /// <summary>
        /// 当前角色
        /// </summary>
        public Role Current { get; set; }

        /// <summary>
        /// 当前操作
        /// </summary>
        public IList<Operation> Operations { get; set; }


        /// <summary>
        /// 
        /// </summary>
        public RoleIndexModel()
        {
            this.Roles = new List<Role>();
        }

        public RoleIndexModel(ICollection<Role> roles)
        {
            this.Roles = roles.ToList();
            if (this.Roles != null && this.Roles.Count > 0)
                this.Current = this.Roles.FirstOrDefault();
        }

        public RoleIndexModel(ICollection<Role> roles, int? index)
        {
            this.Roles = roles.ToList();
            if (index != null && index.HasValue && this.Roles != null && index.Value < this.Roles.Count)
                this.Current = this[index.Value];
            else
                this.Current = this.Roles.FirstOrDefault();
        }

        public RoleIndexModel(ICollection<Role> roles, int? index, ICollection<Operation> operations)
        {
            this.Roles = roles.ToList();
            if (index != null && index.HasValue && this.Roles != null)
                this.Current = this[index.Value];
            else
                this.Current = this.Roles.FirstOrDefault();
            this.Operations = operations.ToList();
        }


        #region  索引
        public Role this[int id]
        {
            get
            {
                Role role = null;
                foreach (var item in this.Roles)
                {
                    role = item.Id == id ? item : null;
                    if (role != null)
                        break;
                }
                return role;
            }
        }
        #endregion





    }
}
